from multiprocessing import Process
import os

class CustomProcess(Process):
    def __init__(self, name):
        super().__init__()
        self.name = name

    def run(self):
        """子进程要执行的任务"""
        print(f"子进程{os.getpid()} - {self.name} 开始执行")

if __name__ == '__main__':
    print(f"父进程{os.getpid()}开始执行")

    # 创建子进程
    process1 = CustomProcess("进程1")
    process2 = CustomProcess("进程2")

    # 启动子进程
    process1.start()
    process2.start()

    # 等待子进程完成
    process1.join()
    process2.join()

    print(f"父进程{os.getpid()}执行完毕")